package com.leetcode.algorithm.y22.m07;

/**
 * 633. 平方数之和
 * 
 * https://leetcode.cn/problems/sum-of-square-numbers/
 * 
 * @author jie.deng
 *
 */
class Question0633Solution01 {
	
	public boolean judgeSquareSum(int c) {
		int left = 0;
		int right = (int) Math.sqrt(c);
		int leftPow = left * left;
		int rightPow = right * right;
		while (left <= right) {
			if ((long) leftPow + rightPow == c) {
				return true;
			} else if ((long) leftPow + rightPow < c) {
				left++;
				leftPow = left * left;
			} else {
				right--;
				rightPow = right * right;
			}
		}
		return false;
	}
    
}